/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-10-15
 * Time: 14:56
 */
//求一个数组中出现数字个数超过该数组一半的数组
//方法一 排序。先排序，找出最中间的数，然后在遍历
import java.util.*;
public class Solution {
    public int MoreThanHalfNum_Solution(int []array){
            if(array==null||array.length==0){
                return 0;
            }
            int count=0;
            Arrays.sort(array);
            int midNum=array[array.length/2];
            for(int i=0;i<array.length;i++){
                if(array[i]==midNum){
                    count++;
                }
            }
            if(count>array.length/2){
                return midNum;
            }
return 0;
    }
}
